﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using NerdDinnerMVC.Models;
using NerdDinnerMVC.NerdDinnerService;

namespace NerdDinnerMVC.Controllers
{
    public class SearchController : Controller
    {
        
        //
        // AJAX: /Search/SearchByLocation
        [HttpPost]
        public ActionResult SearchByLocation(float longitude, float latitude)
        {
            var proxy = new DinnerBusinessObject();
            var dinners = proxy.FindByLocation(latitude, longitude);
            var jsonDinners = from dinner in dinners
                                                 select new JsonDinner
                                                            {
                                                                DinnerId = dinner.DinnerId,
                                                                Latitude = dinner.Latitude,
                                                                Longitude = dinner.Longitude,
                                                                Title = dinner.Title,
                                                                Description = dinner.Description,
                                                                RSVPCount = dinner.NumberOfRSVPs
                                                            };
            var data = jsonDinners.ToList();
            return Json(data);
        }
    }
}